package com.hl.sfzy.controller;

import com.hl.sfzy.constant.CommonConstant;
import com.hl.sfzy.constant.Result;

import com.hl.sfzy.entity.SysIntegral;
import com.hl.sfzy.service.SysIntegralService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class SysIntegralController {
    @Autowired
    private SysIntegralService sysIntegralService;

    @PostMapping("/sysIntegral")
    public Result add(@RequestBody SysIntegral sysIntegral){
        int num = sysIntegralService.add(sysIntegral);
        return  num>0?Result.success():Result.error();
    }
    @DeleteMapping("/sysIntegral/{userid}")
    public Result remove(@PathVariable("userid") Integer userid){
        int num = sysIntegralService.remove(userid);
        return  num>0?Result.success():Result.error();
    }

    @DeleteMapping("/sysIntegral")
    public Result removeBatch(Integer[] ids){
        int num = sysIntegralService.removeBatch(ids);
        return  num>0?Result.success():Result.error();
    }

    @PutMapping("/sysIntegral")
    public Result edit(@RequestBody SysIntegral sysIntegral){
        int num = sysIntegralService.edit(sysIntegral);
        return  num>0?Result.success():Result.error();
    }

    @GetMapping("/sysIntegral/{userid}")
    public Result  findById(@PathVariable("userid") Integer userid){
        SysIntegral byId = sysIntegralService.findById(userid);
        return Result.success(byId);
    }

    @GetMapping("/sysIntegral")
    public Result  findAll(SysIntegral sysIntegral){
        List<SysIntegral> sysIntegrals = sysIntegralService.find(sysIntegral);
        return Result.success(sysIntegrals);
    }

    @GetMapping("/sysIntegral/page")
    public Result findPage(
            @RequestParam(value = CommonConstant.PAGE_NUM, required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
            @RequestParam(value = CommonConstant.PAGE_SIZE, required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize,
            SysIntegral sysIntegral ) {

        Map<String, Object> map = sysIntegralService.findPage(pageNum, pageSize, sysIntegral);
        return Result.success(map);
    }


}
